local skel = fk.CreateSkill {
  name = "emo__tianming",
  tags = {Skill.Permanent, Skill.Limited},
}

skel:addEffect("active", {
  anim_type = "offensive",
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  card_num = 0,
  prompt = "#emo__tianming",
  target_num = 0,
  on_use = function(self, room, effect)
    local player = effect.from
    room:addPlayerMark(player, "emo__taoni-phase") -- 增加Taoni发动次数
    room:setTag("emo__tianming_clean", true)
    local cards = table.filter(room.draw_pile, function (id)
      return Fk:getCardById(id).trueName == "slash"
    end)
    for i, id in ipairs(cards) do
      if room:getCardArea(id) == Card.DrawPile then
        local tos = room.alive_players
        if #tos == 0 then break end
        room:delay(i < 10 and 250 or 100)
        room:obtainCard(table.random(tos), id, true, fk.ReasonJustMove, player, skel.name)
      end
    end
  end,
})


skel:addEffect(fk.EventPhaseEnd, {
  is_delay_effect = true,
  mute = true,
  priority = 2,
  can_trigger = function (self, event, target, player, data)
    return player.room:getTag("emo__tianming_clean")
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setTag("emo__tianming_clean", false)
    for _, p in ipairs(room.alive_players) do
      local cards = table.filter(p:getCardIds("h"), function (id)
        return Fk:getCardById(id).trueName == "slash"
      end)
      if #cards > 0 then
        room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, skel.name, nil, true)
      end
    end
    room:shuffleDrawPile()
  end,
})

Fk:loadTranslationTable{
  ["emo__tianming"] = "天命",
  [":emo__tianming"] = "持恒技，限定技，出牌阶段，你可以将牌堆所有【杀】随机分给每名角色，并令本阶段〖讨逆〗发动技能次数+1，且本阶段结束时，将每名角色的【杀】置入弃牌堆并洗牌。",
  ["#emo__tianming"] = "天命：你可以将牌堆所有【杀】分发，并令〖讨逆〗次数+1",

  ["$emo__tianming1"] = "",
  ["$emo__tianming2"] = "",
}


return skel
